$(window).resize(function () // 绑定到窗口的这个事件中
    {
        remResize()
    });
const UPLOAD_FILE = 'http://www.hrqidian.com/api/upload/file';
const UPLOAD_IMG = 'http://www.hrqidian.com/api/upload/image';

function remResize() {
    let designSize = 1920; // 设计图尺寸
    let html = document.documentElement;
    let wW = html.clientWidth; // 窗口宽度

    if (wW <= 1366) {
        wW = 1366
        $("body").css("width", "1366px")
        $("body").css("overflow", "auto")
    } else {
        $("body").css("width", wW + "px")
    }
    let rem = wW * 100 / designSize;
    document.documentElement.style.fontSize = rem + 'px';
}
$(() => {
    $.ajaxSetup({
        contentType: 'application/json;charset=utf-8',
    });
    remResize()
})

function apiAjax(url, method, data, success, erro) {
    if (method != 'get') {
        data['_token'] = $('meta[name="_token"]').attr('content');
    }
    $.ajax({
        type: method,
        url: url,
        contentType: 'application/json;charset=utf-8',
        data: method != 'get' ? JSON.stringify(data) : data,
        success: (res) => {
            success(res);

        },
        error: (err) => {
            erro();
            if (err.status == 307) {
                window.location.href = "/login";
            }else{
                window.$message('服务器内部错误，请稍后重试！！！')
            }
        },
    })
}

function setCookie(name, value) {
    var exp = new Date();
    exp.setTime(exp.getTime() + 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}

function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}

function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 60 * 60 * 1000);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";path=/";
}
// 获取地址栏参数

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]);
    return null;

}
//设置监听sessionStorage 后
var orignalSetItem = sessionStorage.setItem;
sessionStorage.setItem = function (key, newValue) {
    var setItemEvent = new Event("setItemEvent");
    setItemEvent[key] = newValue;
    window.dispatchEvent(setItemEvent);
    // console.log(setItemEvent);
    orignalSetItem.apply(this, arguments);
}
//获取监听到的session 对象 先
// window.addEventListener("setItemEvent", (e) => {
//     console.log(e);

// });

//电话号码验证
var validateTel = (rule, value, callback) => {
    var reg = /^((13|14|15|16|17|18|19)[0-9]\d{8})$/;
    if (value == '') {
        callback(new Error('请输入联系电话'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的联系电话!'));
    } else {
        callback();
    }
};
//邮箱验证
var validateEmail = (rule, value, callback) => {
    var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
    if (value == '') {
        callback(new Error('请输入邮箱'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的邮箱!'));
    } else {
        callback();
    }
};
//金额验证
var validatePrice = (rule, value, callback) => {
    var reg = /^\d+(\.\d{1,2})?$/;
    if (value == '') {
        callback(new Error('请输入金额'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的金额(保留两位小数)!'));
    } else {
        if (parseFloat(value) > 999999) {
            callback(new Error('金额需小于999999'));
        } else {
            callback();

        }
    }
};
//金额验证（yuan）
var validatePrice1 = (rule, value, callback) => {
    var reg = /^\d+(\.\d{1,2})?$/;
    if (value == '') {
        callback(new Error('请输入金额'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的金额(保留两位小数)!'));
    } else {
        if (parseFloat(value) > 9999999999) {
            callback(new Error('金额需小于9999999999'));
        } else {
            callback();

        }
    }
};
//金额验证（非负数）
var validatePrice2 = (rule, value, callback) => {
    var reg = /^(0\.?\d{0,2}|[1-9]\d*\.?\d{0,2})$/;
    if (value == '' && value != 0) {
        callback(new Error('请输入金额'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的金额(保留两位小数)!'));
    } else {
        if (parseFloat(value) > 999999) {
            callback(new Error('金额需小于999999'));
        } else {
            callback();

        }
    }
};
//整数验证(有问题)
var validateNum = (rule, value, callback) => {
    var reg = /^\\d+$/;
    if (value == '') {
        callback(new Error('请输入数量'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的数量!'));
    } else {
        if (parseFloat(value) > 999999) {
            callback(new Error('金额需小于999999'));
        } else {
            callback();

        }
    }
};
//正整数验证
var validatePositiveNum = (rule, value, callback) => {
    var reg = /^[0-9]*[1-9][0-9]*$/;
    if (value == '') {
        callback(new Error('请输入数量'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入正确的数量!'));
    } else {
        if (parseFloat(value) > 999999) {
            callback(new Error('金额需小于999999'));
        } else {
            callback();

        }
    }
};
//大与10小于5W验证
var validateNumMoney = (rule, value, callback) => {
    var reg = /^[1-9]\d*00$/;
    if (value == '') {
        callback(new Error('请输入金额'));
    } else if (!reg.test(value)) {
        callback(new Error('请输入100的倍数!'));
    } else {
        if (parseFloat(value) > 50000) {
            callback(new Error('金额需小于2000'));
        } else {
            callback();
        }
    }
};
// var validateNumMoney = (rule, value, callback) => {
//     var reg = /^[1-9]\d*00$/;
//     if (value == '') {
//         callback(new Error('请输入金额'));
//     } else if (!reg.test(value)) {
//         callback(new Error('请输入100的倍数!'));
//     } else {
//         if (parseFloat(value) > 2000) {
//             callback(new Error('金额需小于2000'));
//         } else {
//             callback();
//         }
//     }
// };
